#include <iostream>
#include <sstream>

#include "leonutils/SetOps.hpp"

using oss_t = std::ostringstream;

namespace leon_utl {

StrSet_t split2set( const str_t& src_, char d_ ) {
	StrSet_t tokens;
	if( src_.empty() )
		return tokens;

	size_t start = 0, end = 0;
	while( ( end = src_.find( d_, start ) ) != src_.npos ) {
		tokens.insert( src_.substr( start, end - start ) );
		start = end + 1;
	}
	tokens.insert( src_.substr( start ) );
	tokens.erase( "" );
	return tokens;
};

IntSet_t split2int( const str_t& src_, char d_ ) {

	IntSet_t	int_set;
	auto		str_set = split2set( src_, d_ );

	for( const auto& int_str : str_set )
		int_set.insert( atoi( int_str.c_str() ) );

	return int_set;
};

template <typename K, typename C, typename SA>
str_t to_str( const set_t<K, C, SA>& set_, char d_ ) {

	oss_t oss;
	bool first = true;

	for( const auto& k : set_ ) {
		if( !first )
			oss << d_;
		first = false;

		oss << k;
	}

	return oss.str();
};

template str_t to_str( const IntSet_t&, char );
template str_t to_str( const StrSet_t&, char );

}; //namespace leon_utl

ost_t& operator<<( ost_t& os_, const StrSet_t& s_ ) {
	os_ << '{';
	for( const auto& str : s_ )
		os_ << str << ',';
	return os_ << '}';
};

// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4;
